/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.put.dcs_modeler.visualModelEditor.actions;

import java.util.logging.Logger;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import org.openide.cookies.EditorCookie;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.CookieAction;
import pl.put.dcs_modeler.fileTypeDataLoader.DCSComputingModelDataObject;
import pl.put.dcs_modeler.visualModelEditor.windowComponenets.CFMWindowTopComponent;

public final class ShowComputingModel extends CookieAction
{
    private static Logger log =
            Logger.getLogger( ShowComputingModel.class.getName() );
    
    @Override
    protected void performAction( Node[] activatedNodes )
    {
        log.info( "ShowComputingModel");
        DCSComputingModelDataObject dCSComputingModelDataObject = ( activatedNodes[0].getLookup().lookup( DCSComputingModelDataObject.class ) );
        //  EditorCookie editorCookie = activatedNodes[0].getLookup().lookup( EditorCookie.class );
        // Document doc = editorCookie.getDocument();

        CFMWindowTopComponent win = CFMWindowTopComponent.findInstance( dCSComputingModelDataObject );
       
        //win.getCfmScene().setASTNode( pm.getAST() );
        win.open();
        win.requestActive();
    // TODO use editorCookie
    }

    protected int mode()
    {
        return CookieAction.MODE_EXACTLY_ONE;
    }

    public String getName()
    {
        return NbBundle.getMessage( ShowComputingModel.class, "CTL_ShowComputingModel" );
    }

    protected Class[] cookieClasses()
    {
        return new Class[]
                {
                    EditorCookie.class
                };
    }

    @Override
    protected void initialize()
    {
        super.initialize();
        // see org.openide.util.actions.SystemAction.iconResource() Javadoc for more details
        putValue( "noIconInMenu", Boolean.TRUE );
    }

    public HelpCtx getHelpCtx()
    {
        return HelpCtx.DEFAULT_HELP;
    }

    @Override
    protected boolean asynchronous()
    {
        return false;
    }
}

